<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '../../../../dashboard/mixins/resize'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons1')

      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          formatter: '{a} <br/>{b}: {c} 小时',
          axisPointer: {
            // Use axis to trigger tooltip
            type: 'none' // 'shadow' as default; can also be 'line' or 'shadow'
          },
        },
        legend: {},
        tooltip: {},
        dataset: {
          dimensions: ['product', '计划产量', '实际产量'],
          source: [
            { product: '02-02', 计划产量: 43.3, 实际产量: 85.8,  },
            { product: '02-03', 计划产量: 83.1, 实际产量: 73.4,  },
            { product: '02-04', 计划产量: 86.4, 实际产量: 65.2,  },
            { product: '02-05', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-06', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-07', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-08', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-09', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-10', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-11', 计划产量: 72.4, 实际产量: 53.9,  },
            { product: '02-12', 计划产量: 72.4, 实际产量: 53.9,  },
          ]
        },
        xAxis: { 
          type: 'category',
          axisLine:{
            show: false,
            onZero: true, //刻度线是否在0刻度上
            lineStyle:{
              color:'#999',
              width:1,//这里是为了突出显示加上的
            }
          },
          axisTick:{
            show: false
          },
          splitLine :{
            show: false
          }
        },
        yAxis: {
          axisLine:{
            show: false,
            onZero: true, //刻度线是否在0刻度上
            lineStyle:{
              color:'#999',
              width:1,//这里是为了突出显示加上的
            }
          },
          axisTick:{
            show: false
          },
          splitLine :{
            show: false
          }
        },
        // Declare several bar series, each will be mapped
        // to a column of dataset.source by default.
        series: [
          { 
            type: 'bar', 
            barWidth:'10px' ,
            color: '#5770c2'
          },
          { 
            type: 'bar', 
            barWidth:'10px' ,
            color: '#d99c72'
          },
        ],
        grid: {
          left: '1%',
          right: '2%',
          top: '3%',
          bottom: '2%',
          containLabel: true
        },
      })
    }
  }
}
</script>
